import { lStorage } from '@/utils'

const DURATION = 48 * 60 * 60 //单位：秒
const TCODE_ADMIN = 'ACCESS_TOKEN_ADMIN'

function _getTokenCode() {
  return TCODE_ADMIN
}

export function getToken() {
  // admin端是登录状态，进入user端可以使用代理token
  const adminToken = lStorage.get(TCODE_ADMIN)
  if (adminToken) {
    return adminToken
  }
  return lStorage.get(_getTokenCode())
}

export function setToken(token) {
  lStorage.set(_getTokenCode(), token, DURATION)
}

//  remove 全部token
export function removeAllTokens() {
  lStorage.remove(TCODE_ADMIN)
}
